package com.tianheng.wanzhou.datacollecting.netty.kongyajiR150.receiver.receiverImpl;

import com.baomidou.mybatisplus.extension.service.IService;
import com.tianheng.wanzhou.datacollecting.db.entity.AirCompressorR1502;
import com.tianheng.wanzhou.datacollecting.db.service.IAirCompressorR1502Service;
import com.tianheng.wanzhou.datacollecting.netty.kongyajiR150.receiver.Receiver;
import com.tianheng.wanzhou.datacollecting.util.StrUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Author: yujw
 * @Date: 2020/5/19 13:11
 * @Version 1.0
 */
@Component("r150A2")
public class Air2Receiver extends Receiver {


    @Autowired
    IAirCompressorR1502Service service;

    @Override
    public Object parseMessage(String message, String ip, Integer company, Integer workshop, String machineId) {
        AirCompressorR1502 airCompressorR1502 = new AirCompressorR1502();
        if(message.substring(4,6).equals("10")){
            String str = message.substring(3 * 2).substring(0, 4);
            String binary = StrUtil.hexStr2BinaryStr(str);
            char[] x = binary.toCharArray();
//            AirCompressorR1502 airCompressorR1502 = new AirCompressorR1502();
            airCompressorR1502.setMachineIp(ip);
            airCompressorR1502.setCompany(company);
            airCompressorR1502.setWorkshop(workshop);
            airCompressorR1502.setMachineId(machineId);
            airCompressorR1502.setDriverEStop(Character.digit(x[0], 2));
            airCompressorR1502.setOilReservoirLevel(Character.digit(x[1], 2));
            airCompressorR1502.setSealAirPressureSwitch(Character.digit(x[2], 2));
            airCompressorR1502.setDriverRemoteStart(Character.digit(x[3], 2));
            airCompressorR1502.setDriverRemoteStop(Character.digit(x[4], 2));
            airCompressorR1502.setRemoteUnload(Character.digit(x[5], 2));
            airCompressorR1502.setOilFilterPressureDrop(Character.digit(x[6], 2));
            airCompressorR1502.setAirFilterPressureDrop(Character.digit(x[7], 2));
            airCompressorR1502.setDriverStarterStatus(Character.digit(x[8], 2));
            airCompressorR1502.setCondensationLevel(Character.digit(x[9], 2));
        }
        return airCompressorR1502;
    }

    @Override
    public IService getService() {
        return service;
    }
}
